<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>for map 遍历查询</title>
</head>
<body>
    
    <div class="wrap">
        <input type="text" id="search"> <button id="btn">search</button>
        <p id="result"></p>
    </div>

    <script>
        
        // 这是一个 遍历查询 分数的小例子 （主要练习的是map的遍历查询方法）

        let data = new Map([["a",90],["b",78],["c",32],["d",66]]);
        let btn = document.getElementById("btn");
        let result = document.getElementById("result");
        btn.onclick = function (){
            let val = document.getElementById("search").value;
            if(val.length == 0){
                return result.innerHTML = "你没有输入，请重新输入";
            }
            if(!data.has(val)){
                return result.innerHTML = "没有这个人，请确认后再输入";
            }
            let score = data.get(val);
            let txt = score>60?"恭喜你，通过考试!":"很遗憾，你未通过考试！";
            result.innerHTML = txt + ",你的考试分数为" + score;
        };
        

    </script>

</body>
</html>